import 'package:flutter/material.dart';
import 'package:flutternote/router.dart';

void main() {
  runApp(new MaterialApp(
      title: 'My app', // used by the OS task switcher
      home: new ContentLayout(
          ["文字", "button", "Image", "动画", "列表", "带特效的页面转换"])));
}

class ContentLayout extends StatelessWidget {
  final List<String> strList;

  ContentLayout(this.strList);

  @override
  Widget build(BuildContext context) {
    return new Scaffold(
        appBar: new AppBar(
          title: new Text("flutter note"),
        ),
        body: ListView.builder(
            physics: BouncingScrollPhysics(),
            scrollDirection: Axis.vertical,
            itemCount: strList.length,
            itemBuilder: (context, index) {
              return new GestureDetector(
                onTap: () {
                  handleTap(context, index);
                },
                child: new Container(
                  padding: const EdgeInsets.all(10),
                  child: new Text(
                    strList[index],
                    style: new TextStyle(color: Colors.blue),
                  ),
                ),
              );
            }));
  }

  void handleTap(BuildContext context, int index) {
    var selectedText = strList[index];
    if (selectedText == "带特效的页面转换") {
      Router.toRouterShow(context);
    } else if (selectedText == "动画") {
      Router.toAnimation(context);
    } else if (selectedText == "Image") {
      Router.toImage(context);
    } else if (selectedText == "button") {
      Router.toButton(context);
    } else if (selectedText == "文字") {
      Router.toText(context);
    } else if (selectedText == "列表") {
      Router.toList(context);
    }
  }
}
